-- UIErrorInfo
-- Create by zouyb Jan/25/2015
-- 系统错误信息收集界面

UIErrorInfo = class("UIErrorInfo",function()
    return cc.Layer:create()
end)

function UIErrorInfo.create()
    return UIErrorInfo.new();
end

-- 内部函数声明
local resize;

-- 构造函数
function UIErrorInfo:ctor()
    self:setName("UIErrorInfo");

    -- 初始化
    local node = cc.CSLoader:createNode("layout/setting/ErrorInfo.csb");
    self:addChild(node);
    self.node = node;

    -- 需要显示在头部菜单上面
    self:setLocalZOrder(UIMgr.BONUS_NOTIFY_ZORDER + 100000);

    local errorLabel = findChildByName(self.node, "CT/scrollview/error");
    TextStyleM.setTextStyle(errorLabel, TextStyleM.TEXT_SIZE_MINI, TextStyleM.TEXT_COLOR_BLACK);

    local str = "";
    local tracebackList = getTracebackList();
    for _, err in pairs(tracebackList) do
        str = str .. "\n" .. err;
    end

    errorLabel:setString(str);

    local errorInfoLabel = findChildByName(self.node, "CT/error_info_label");
    TextStyleM.setTextStyle(errorInfoLabel, TextStyleM.TEXT_SIZE_MIDDLE, TextStyleM.TEXT_COLOR_BROWN_YELLOW, true);
    errorInfoLabel:setString(getLocStr("error_info"));

    local descLabel = findChildByName(self.node, "CT/desc");
    TextStyleM.setTextStyle(descLabel, TextStyleM.TEXT_SIZE_MINI, TextStyleM.TEXT_COLOR_DARK_RED);

    -- 说明文字就不要换行了，设置一下
    descLabel:getVirtualRenderer():setMaxLineWidth(100 * TextStyleM.TEXT_SIZE_MINI);

    descLabel:setString(getLocStr("error_info_tip"));

    -- 注册返回按钮点击事件
    local btnBack = findChildByName(self.node, "BT/btn_back");
    local function onBackClick(sender, eventType)
        if eventType == ccui.TouchEventType.ended then
            -- 关闭当前界面
            AudioM.playFx("button_return");
            UIMgr.getCurrentScene():removeFormByName("UIErrorInfo");
        end
    end
    AddBackEventHandler(self, btnBack, onBackClick);
    TextStyleM.setTextStyle(btnBack, TextStyleM.TEXT_SIZE_MIDDLE, TextStyleM.TEXT_COLOR_BROWN_YELLOW, true);
    btnBack:setTitleText(getLocStr("btn_text_back"));

    -- 适配
    resize(node);
end

-- 适配
function resize(node)
    -- bg居中显示并充满整个屏幕
    AlignM.fitToScreen(node, "bg");

    -- CT居中并缩放至合适大小
    AlignM.alignToCenter(node, "CT");

    -- BT置于底部并缩放至合适大小
    AlignM.alignToBottomCenter(node, "BT");
end
